package com.example.myap.viewModule;

import android.annotation.SuppressLint;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.example.myap.Bean.BannerBean;
import com.example.myap.MainActivity;
import com.example.myap.R;
import com.example.myap.databinding.ActivityMainBinding;
import com.stx.xhb.androidx.XBanner;
import com.sunnybear.framework.library.base.BaseViewModule;
import com.sunnybear.framework.tools.Toasty;

import java.util.ArrayList;

/**
 * @ClassName ActivityMainViewModule
 * @Description TODO
 * @Author zhaoyiming
 * @Date 2021/12/27 10:15 上午
 */
public class ActivityMainViewModule extends BaseViewModule<MainActivity, ActivityMainBinding> {
    private ArrayList<BannerBean> setBannerData = new ArrayList<>();
    public ActivityMainViewModule(MainActivity mainActivity, ActivityMainBinding viewDataBinding) {
        super(mainActivity, viewDataBinding);
    }

    @Override
    public void init() {

        setBannerData.add(new BannerBean(R.mipmap.icon_ban1, "第一个"));
        setBannerData.add(new BannerBean(R.mipmap.icon_ban2, "第二个"));
        setBannerData.add(new BannerBean(R.mipmap.icon_ban3, "第三个"));
        mViewDataBinding.banner.setBannerData(setBannerData);
        mViewDataBinding.banner.loadImage(new XBanner.XBannerAdapter() {

            @SuppressLint("CheckResult")
            @Override
            public void loadBanner(XBanner banner, Object model, View view, int position) {
                RequestOptions options = new RequestOptions();
                options.transform(new MultiTransformation<>(new CenterCrop()),new RoundedCorners(24))
                        .priority(Priority.HIGH);
                Glide.with(mPresenter).load(setBannerData.get(position).getXBannerUrl()).placeholder(R.mipmap.ic_launcher_round).error(R.mipmap.ic_launcher_round).apply(options).into((ImageView) view);
            }
        });
        mViewDataBinding.banner.setOnItemClickListener(new XBanner.OnItemClickListener() {
            @Override
            public void onItemClick(XBanner banner, Object model, View view, int position) {
                Toasty.center(mPresenter,"sss").show();
            }
        });
        mViewDataBinding.banner.startAutoPlay();
    }
}
